package com.example.studygo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.studygo.model.User;
import com.example.studygo.model.UserDemo;
import com.example.studygo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @author 路老师
 * @date 2025/8/13
 * 无精神，不编程！无乐趣，不编程！
 * “调试：与bug共舞的艺术。”
 */
@Controller
@ResponseBody
public class TestController {

    @Autowired
    private UserService userService;

    @RequestMapping("/ok")
    public String test()
    {
        return "1111";
    }

    @RequestMapping("/ok1")
    public String test1()
    {
        return "redirect:/test.html";
    }

    @RequestMapping("/ok2")
    public UserDemo test2()
    {
        UserDemo userDemo = new UserDemo();
        userDemo.setUserId(1);
        userDemo.setUsername("akui");
        userDemo.setPassword("123");
        return userDemo;
    }


    @RequestMapping("/save")
    public void test5(){
        User user = new User();
        user.setUserName("abc123");
        user.setUserPassword("123456");
        user.setUserSex(1);
        user.setUserHobbys("玩_吃_喝");
        user.setUserAddress("陕西省西安市");
        user.setUserEmail("4234234@qq.com");
        user.setUserBirthday(new Date());
        userService.save(user);
    }

    /**
     * 查询条件
     */
    @RequestMapping("/testme")
    public void selectMe()
    {
        List<User> ok = userService.ok();
        System.out.println("ok = " + ok);
//        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
//        userQueryWrapper.eq("user_name","admin")
//                .or().eq("user_password","12345");
//        List<User> list = userService.list(userQueryWrapper);
//        System.out.println("list = " + list);
    }
}
